declare global {
  interface Window {
    gtag?: (...args: any[]) => void;
    dataLayer?: any[];
    webkitSpeechRecognition?: any;
    SpeechRecognition?: any;
  }
}

// 全局常用类型
export type ID = string | number;
export type Timestamp = number;
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export type RequiredFields<T, K extends keyof T> = T & Required<Pick<T, K>>;

// API 响应通用类型
export interface APIResponse<T = any> {
  success: boolean;
  data: T;
  message?: string;
  code?: number;
  timestamp?: number;
}

export interface PaginatedResponse<T> extends APIResponse<T[]> {
  pagination: {
    page: number;
    pageSize: number;
    total: number;
    totalPages: number;
    hasNext: boolean;
    hasPrev: boolean;
  };
}

// 错误类型
export interface APIError {
  code: string;
  message: string;
  details?: Record<string, any>;
  timestamp: number;
}

// 用户行为追踪类型
export interface UserBehavior {
  userId: string;
  sessionId: string;
  timestamp: number;
  action: 'click' | 'scroll' | 'search' | 'dwell' | 'share' | 'bookmark';
  target: {
    type: 'result' | 'suggestion' | 'filter' | 'recommendation';
    id: string;
    metadata?: Record<string, any>;
  };
  context: {
    query?: string;
    position?: number;
    viewport?: { width: number; height: number };
    userAgent?: string;
    referrer?: string;
  };
}

// 配置类型
export interface AppConfig {
  api: {
    baseUrl: string;
    timeout: number;
  };
  features: {
    voiceSearch: boolean;
    imageSearch: boolean;
    analytics: boolean;
    recommendations: boolean;
  };
  performance: {
    virtualScrollThreshold: number;
    cacheSize: number;
    debounceMs: number;
  };
  development: {
    debugMode: boolean;
    mockApi: boolean;
  };
}

// 主题类型
export type Theme = 'light' | 'dark' | 'auto';

// 语言类型
export type Language = 'zh-CN' | 'en-US' | 'ja-JP' | 'ko-KR';

// 设备类型
export type DeviceType = 'desktop' | 'tablet' | 'mobile';

// 网络状态类型
export type NetworkStatus = 'online' | 'offline' | 'slow';

export {};
